package db.exchange.market;

import java.io.*;
import java.net.*;
//import java.util.*;
import java.util.concurrent.BlockingQueue;
//import java.util.concurrent.LinkedBlockingDeque;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Acceptor implements Runnable {

	int port;
	BlockingQueue<Socket> socketQueue;

	public Acceptor(BlockingQueue<Socket> socketQueue, int port) {
		this.socketQueue = socketQueue;
		this.port = port;
	}

	Logger logger = Logger.getLogger("log.log");

	public void run() {
		Socket connection = null;
		ServerSocket providerSocket;
		try {
			providerSocket = new ServerSocket(port, 10);
			logger.log(Level.INFO, "Waiting for connection");
			while (true ) {
			connection = providerSocket.accept();
			System.out.println("Connection received from "
					+ connection.getInetAddress().getHostName());
			socketQueue.add(connection);
			System.out.println("CONNECTION PUTTED");
		}
		} catch (IOException ioException) {
			ioException.printStackTrace();
		}

	}
}
